/*
 * Created on 2005-3-23
 *
 */
package com.hd123.rumba.impex;

import java.util.Date;

import com.hd123.rumba.domain.Domain;

/**
 * @author caili
 */
public class ImpexResult {
  public static final int DEFAULT = -1;
  public static final int IMPORT = 0;
  public static final int EXPORT = 1;

  private int total = 0;
  private int inserted = 0;
  private int updated = 0;
  private int deleted = 0;
  private int success = 0;
  private int fail = 0;
  private StringBuffer messages = new StringBuffer();
  private Date startTime = new Date();
  private Date endTime = null;
  private String code;
  private String hint;

  // 下面这些属性作为exportToxxx的参数传递
  private Domain counterPart;
  private Domain objectDomain;
  private String exportId;
  private int size = 0;
  
  public int getSize() {
    return size;
  }
  public void setSize(int size) {
    this.size = size;
  }
  public String getExportId() {
    return exportId;
  }
  public void setExportId(String exportId) {
    this.exportId = exportId;
  }
  public Domain getObjectDomain() {
    return objectDomain;
  }
  public void setObjectDomain(Domain objectDomain) {
    this.objectDomain = objectDomain;
  }
  public Domain getCounterPart() {
    return counterPart;
  }
  public void setCounterPart(Domain counterPart) {
    this.counterPart = counterPart;
  }
  public ImpexResult(String code) {
    this.code = code;
  }

  public Date getEndTime() {
    return endTime;
  }

  public void setEndTime(Date endTime) {
    this.endTime = endTime;
  }

  public Date getStartTime() {
    return startTime;
  }

  public void setStartTime(Date startTime) {
    this.startTime = startTime;
  }

  public void setMessages(StringBuffer messages) {
    this.messages = messages;
  }

  public int getDeleted() {
    return deleted;
  }

  public void setDeleted(int deleted) {
    this.deleted = deleted;
  }

  public int getFail() {
    return fail;
  }

  public void setFail(int fail) {
    this.fail = fail;
  }

  public StringBuffer getMessages() {
    return messages;
  }

  public int getInserted() {
    return inserted;
  }

  public void setInserted(int inserted) {
    this.inserted = inserted;
  }

  public int getSuccess() {
    return success;
  }

  public void setSuccess(int success) {
    this.success = success;
  }

  public int getTotal() {
    return total;
  }

  public void setTotal(int total) {
    this.total = total;
  }

  public int getUpdated() {
    return updated;
  }

  public void setUpdated(int updated) {
    this.updated = updated;
  }

  public void incSuccess() {
    success++;
  }

  public void incFail() {
    fail++;
  }

  public void incInserted() {
    inserted++;
  }

  public void incDeleted() {
    deleted++;
  }

  public void incUpdated() {
    updated++;
  }

  public ImpexResult addMessage(int position, String message) {
    messages.append("第" + position + "笔: " + message);
    return this;
  }

  public ImpexResult addMessage(String message) {
    messages.append(message);
    return this;
  }

  public String getMessage(int style) {
    StringBuffer sb = new StringBuffer();
    sb.append(code + ": ");
    sb.append(getMessages());
    sb.append(" ");
    switch (style) {
    case IMPORT: {
      if (total > 0) {
        sb.append("共处理" + total + "笔. ");
        sb.append("添加" + inserted + "笔, ");
        sb.append("更新" + updated + "笔. ");
      }
      break;
    }
    case EXPORT: {
      sb.append("共导出" + total + "笔. ");
      break;
    }
    }
    return sb.toString();
  }

  public String getHint() {
    return hint;
  }

  public void setHint(String hint) {
    this.hint = hint;
  }

  public String getCode() {
    return code;
  }
  public void setCode(String code) {
    this.code = code;
  }
}
